import ProForm, { ProFormText } from '@ant-design/pro-form';
import { Modal, Spin } from 'antd';
import { useUpdateEffect } from '@umijs/hooks';
import { useRef } from 'react';

const SaveForm = (props) => {
    const { modalVisible, onCancel, onSubmit, loading, record } = props;

    const formRef = useRef();

    useUpdateEffect(() => {
        if (modalVisible && !record.id) {
            // generateAppSecretRequest.run({});
        }
    }, [modalVisible, record]);
    return (
        <Modal
            destroyOnClose
            title={'配置'}
            open={modalVisible}
            onCancel={() => onCancel()}
            footer={null}
        >
            <Spin tip="正在处理..." spinning={loading}>
                <ProForm
                    formRef={formRef}
                    onFinish={async (value) => {
                        const params = value;
                        if (record.id) {
                            params.id = record.id;
                        }
                        await onSubmit(params);
                    }}
                    initialValues={{ ...record }}
                >
                    <ProFormText
                        name="publicAddress"
                        label="服务地址"
                        placeholder="请输入服务地址"
                        rules={[{ required: true, message: '请输入服务地址！' }]}
                    />
                 
                </ProForm>
            </Spin>
        </Modal>
    );
};

export default SaveForm;
